from django.contrib.auth.hashers import make_password
from rest_framework import serializers

from users.models import User


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model=User
        fields=['id','username','email','mobile','password']
        extra_kwargs = {
            "password":{"write_only":True}
        }

        def validate(self, attrs):
            attrs['is_staff']=True
            attrs['password'] = make_password(attrs['password'])
            return attrs